class Element:
    def __init__(self,items):
            self.itemset = []
            if isinstance(items, list):
                for item in items:
                    self.addItem(item)
                            
    def addItem(self, item):
           i=0
           for i in range(0, len(self.itemset)):
               if item < self.itemset.__getitem__(i):
                   break
           self.itemset.insert(i, item)
           
    def getItems(self):
           return self.itemset
           
    def getLastItem(self):
           if len(self.itemset) > 0:
               return self.itemset[len(self.itemset) - 1]
           else:
               print "Error Element.getLastItem()"
               return 0

    def isContainIn(self, e):
        if isinstance(e, Element):
            if len(self.itemset) > len(getattr(e, 'itemset')):
                return None
            
            i=0
            j=0
            while (j < len(getattr(e, 'itemset')) and i < len(self.itemset)):
                         if int(self.itemset[i]) == int(getattr(e, 'itemset')[j]):
                             i += 1
                             j += 1
                         else:
                             j += 1
            if i == len(self.itemset):
                return 1
            else :
                return 0
        
    def getWithoutFirstItem(self):
        e = Element(1)
        for i in range(1,len(self.itemset)):
            e.addItem(int(self.itemset.__getitem__(i)))
        return e
    
    
    def getWithoutLastItem(self):
        e = Element(1)
        for i in range(0,len(self.itemset)-1):
            e.addItem(int(self.itemset.__getitem__(i)))
        return e
    
    def removeItem(self,i):
        if i<len(self.itemset):
            return self.itemset.pop(i)
        print "error"
        return -1
    
    def compareTo(self,o):
        if isinstance(o, Element):
            r=0
            i=0
            j=0
            while (i<len(self.itemset) and j<len(getattr(o, 'itemset'))):
                if int(self.itemset.get(i)) < int(getattr(o, 'itemset').get(j)):
                    r=-1
                    break
                elif(int(self.itemset.get(i)) > int(getattr(o, 'itemset').get(j))):
                    r=1
                    break
                i+=1
                j+=1
            if r==0:
                if len(self.itemset)>len(getattr(o, 'itemset')):
                    r=1
                elif len(self.itemset)<len(getattr(o, 'itemset')):
                    r=-1
            return r
    
    def size(self):
        return len(self.itemset)            
                    
    def clone(self):
        clone = Element(1)
        for i in self.itemset:
            clone.addItem(i)
        return clone
    
    def equalsTo(self,o):
        equal =1
        if isinstance(o, Element):
            if len(self.itemset) != len(getattr(o, 'itemset')):
                equal =0
            for i in range(0, len(self.itemset)):
                   if int(self.itemset[i]) < int(getattr(o, 'itemset')[i]):
                       equal =0
            return equal
    def __repr__(self):
        s=[]
        if len(self.itemset)>1:
            s.append("(")
        for i in range(0, len(self.itemset)):
            s.append(str(self.itemset[i])) 
            if i<(len(self.itemset)-1):
                s.append(",")
        if len(self.itemset)>1:
            s.append(")")
#        print "1qwqwqw ",''.join(s.__str__())
        return ''.join(s)
    
    def __str__(self):
        s=[]
        if len(self.itemset)>1:
            s.append("(")
        for i in range(0, len(self.itemset)):
            s.append(str(self.itemset[i])) 
            if i<(len(self.itemset)-1):
                s.append(",")
        if len(self.itemset)>1:
            s.append(")")
#        print "1qwqwqw ",''.join(s.__str__())
        return ''.join(s)


